package com.practice.car.cardataapp.controller;

import com.practice.car.cardataapp.schelduer.scrapy.ScrapyScheduler;
import com.practice.car.cardataapp.schelduer.spark.Schedule;
import com.practice.car.cardataapp.util.R;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * car-data-app project
 *
 * @author ZhangMingXing
 * @date 2020/9/9
 */
@RestController
@RequestMapping("scheduler")
public class SchedulerController {

	@GetMapping("spark/change")
	public R sparkChange(@RequestParam("bool") Boolean bool) {
		Schedule.isContinue = bool;
		return R.create();
	}

	@GetMapping("spark/startImmediately")
	public R startImmediagtely() {
		Schedule.begin();
		return R.create();
	}

	@GetMapping("scrapy/change")
	public R scrapyBegin(@RequestParam("bool") Boolean bool) {
		ScrapyScheduler.isContinue = bool;
		return R.create();
	}

	@GetMapping("scrapy/startImmediately")
	public R scrapyStartImmediately() {
		ScrapyScheduler.run();
		return R.create();
	}

	@GetMapping("spark/status")
	public R sparkStatus() {
		return R.create().put("bool", Schedule.isContinue);
	}

	@GetMapping("scrapy/status")
	public R scrapyStatus() {
		return R.create().put("bool", ScrapyScheduler.isContinue);
	}
}
